<style>
.jy2-headertop {position: absolute; min-height: 100%;padding-top:0.3rem;padding-bottom:0.3rem;margin-top:-2rem;border-top-right-radius:1rem;border-top-left-radius:1rem;}
.fui-header:after {
	border-bottom: 0 solid #D9D9D9;
}
</style>
<div class='fui-page fui-page-current' ng-if="pagedata.op=='list'">
	<div class="fui-header" style="background:none">
				<div class="fui-header-left">
					<a class="back" href="javascript:" ng-click="goback()"></a>
				</div>
				<div class="title bold" style="font-size:1rem;">{{pagedata.type==1?'寄件地址':'收货地址'}}</div>
				<div class="fui-header-right" style="padding-right:0.5rem;">
					<i class="icon jinyunicon icon-liaotian" ng-click="access_json('jy_kuaidisys/member.index/')" style="font-size: 1rem;"></i>
				</div>
	</div>
    <div class='fui-content'>
		<div class='content-empty' ng-show="pagedata.list.length<=0">
			<i class='fa fa-comment-o'></i>
			<br/>您还没有任何{{pagedata.type==1?'寄件地址':'收货地址'}}
		</div>
		<div class="fui-list-group address-item" style='margin-top:5px;' ng-repeat="item in pagedata.list">
			<div  class="fui-list" >
			<div class="fui-list-inner">
				<div class="title" ng-click="modal_result(item)"><span class='realname'>{{item.name}}</span> <span class='mobile'>{{item.mobile}}</span></div>
				<div class="text" ng-click="modal_result(item)"><span class='address'>{{item.pcd.province}}&nbsp{{item.pcd.city}}&nbsp{{item.pcd.district}}&nbsp{{item.pcd.street}}&nbsp{{item.address}}</span></div>
				<div class='bar' >
				<span class='pull-right'>
					<a class="external" href="javascript:;" ng-click="access_json('jy_kuaidisys/member.address/edit/id='+item.id)">
					<i class='fa fa-edit'></i> 编辑
					</a>
					&nbsp;&nbsp;
					<a class='external' href="javascript:;" ng-click="post({},'jy_kuaidisys/member.address/del/id='+item.id)">
					<i class='fa fa-trash-o'></i> 删除
					</a>
				</span>
				<label class='radio-inline'>
					<input type="radio" class="fui-radio  fui-radio-danger" ng-checked="item.isdefault==1" ng-click="modal_post({},'jy_kuaidisys/member.address/set/id='+item.id)"/> 设置默认
				</label>
				</div>
			</div>
			</div>
		</div>
		<div class='fui-navbar'>
			<a href="javascript:;" class='nav-item btn btn-danger external' ng-click="access_json('jy_kuaidisys/member.address/edit/')"><i class="fa fa-plus-square-o"></i> 新建地址</a>
		</div>
    </div>
</div>
<div class='fui-page  fui-page-current' ng-if="pagedata.op=='edit'">
	<div class="fui-header" style="background:none">
				<div class="fui-header-left">
					<a class="back" href="javascript:" ng-click="goback()"></a>
				</div>
				<div class="title bold" style="font-size:1rem;">{{pagedata.item.id ?'编辑地址':'新建地址'}}</div>
				<div class="fui-header-right" style="padding-right:0.5rem;">
					<i class="icon jinyunicon icon-liaotian" ng-click="access_json('jy_kuaidisys/member.index/')" style="font-size: 1rem;"></i>
				</div>
	</div>
    <div class='fui-content'>
			<div ng-if="pagedata.wxapp_id==0 && pagedata.openid && !pagedata.item.id && pagedata.type==1" class="weui_cells_title" style="margin:0.5rem;padding-left:0;padding-right:0">微信地址<span ng-click="pagedata.openAddress()" class="r-f">一键添加 <i class="icon icon-more" style="font-size:0.6rem;color:#999"></i></span></div>
            <div class='fui-cell-group'>
                <div class='fui-cell'>
                    <div class='fui-cell-label'>{{pagedata.type==1?'寄件':'收货'}}人</div>
                    <div class='fui-cell-info'><input type="text" ng-model="pagedata.item.name" placeholder="{{pagedata.type==1?'寄件':'收货'}}人" class="fui-input"/></div>
                </div>
                <div class='fui-cell'>
                    <div class='fui-cell-label'>联系电话</div>
                    <div class='fui-cell-info'><input type="tel" ng-model="pagedata.item.mobile" placeholder="联系电话"  class="fui-input"/></div>
                </div>

                <div class="fui-cell">
					<div class="fui-cell-label ">所在城市</div>
					<div class="fui-cell-label" style="width:28%">
						<select ng-model="pagedata.item.pcd.province" class="form-control tpl-province">
						<option value="" selected="selected">省份</option>
						<option ng-repeat="(value,data) in pagedata.province" value="{{value}}" ng-selected="pagedata.item.pcd.province==value">{{value}}</option>
						</select>
					</div>
					<div class="fui-cell-label" style="width:28%">
						<select ng-model="pagedata.item.pcd.city" class="form-control tpl-city">
						<option value="" selected="selected">城市</option>
						<option ng-repeat="(value,data) in pagedata.province[pagedata.item.pcd.province]" value="{{value}}" ng-selected="pagedata.item.pcd.city==value">{{value}}</option>
						</select>
					</div>
					<div class="fui-cell-label" style="width:28%">
						<select ng-model="pagedata.item.pcd.district" class="form-control tpl-district">
						<option value="" selected="selected">区县</option>
						<option ng-repeat="(value,data) in pagedata.province[pagedata.item.pcd.province][pagedata.item.pcd.city]" value="{{value}}" ng-selected="pagedata.item.pcd.district==value">{{value}}</option>
						</select>
					</div>
					<div class="fui-cell-label" style="width:28%">
						<select ng-model="pagedata.item.pcd.street" class="form-control tpl-district">
						<option value="" selected="selected">街道</option>
						<option ng-repeat="value in pagedata.province[pagedata.item.pcd.province][pagedata.item.pcd.city][pagedata.item.pcd.district]" value="{{value}}" ng-selected="pagedata.item.pcd.street==value">{{value}}</option>
						</select>
					</div>
				</div>
                <div class='fui-cell'>
                    <div class='fui-cell-label'>详细地址</div>
                    <div class='fui-cell-info'><input type="text" ng-model="pagedata.item.address" placeholder='街道，楼牌号等'  class="fui-input"/></div>
                </div>
            </div>
            <a id="btn-submit" class='external btn btn-danger block' ng-click="modal_post(pagedata.item,'jy_kuaidisys/member.address/post/')">保存地址</a>
         </form>
    </div>
</div>
<div class="fui-page fui-page-current" ng-if="pagedata.op=='choose'">
    <div class="fui-content navbar">
		<div id="l-map"></div>
		<div class="weui_cells weui_cells_radio2">
				<label class="weui_cell weui_check_label" ng-repeat="item in pagedata.addresslist">
					<div class="weui_cell_bd weui_cell_primary">
						<span>{{item.title}}</span>
					</div>
					<div class="weui_cell_ft">
						<input type="radio" class="weui_check">
						<span class="weui_icon_checked"></span>
					</div>
				</label>
	   </div>
	</div>
	<div class="fui-navbar" style="background:#09ba07;">
		<a href="javascript:;" ng-click="pagedata.submit(0);" class="nav-item" style="color:#fff">完成</a>
	</div>
<script type="text/javascript">
// 百度地图API功能
window.scope.location(function(res){
			if(scope.pagedata.op=='choose'){
				require(['map'], function(BMap){
					var map = new BMap.Map("l-map");
					var lng=res.lat_lng.lng ? res.lat_lng.lng : '113.941134';
					var lat=res.lat_lng.lat ? res.lat_lng.lat : '22.546011';
					var point = new BMap.Point(lng, lat);
					map.centerAndZoom(point, 15);
					// 编写自定义函数,创建标注
					function addMarker(point){
					  var marker = new BMap.Marker(point);
					  map.addOverlay(marker);
					}
					addMarker(point);
				});
			}else{
				if(scope.pagedata.op=='edit'){
					scope.pagedata.item.pcd = res.addressComponents;
				}else if (scope.pagedata.op=='edit'){
					scope.pagedata.item.pcd = res.addressComponents;
				}
				scope.$evalAsync();
			}
});
scope.pagedata.openAddress=function (){
	wx.openAddress({
		  success: function (res) {
			scope.pagedata.item={}
			scope.pagedata.item.name = res.userName; // 收货人姓名
			scope.pagedata.item.pcd={}
			scope.pagedata.item.pcd.province = res.provinceName; // 国标收货地址第一级地址（省）
			scope.pagedata.item.pcd.city = res.cityName; // 国标收货地址第二级地址（市）
			scope.pagedata.item.pcd.district = res.countryName; // 国标收货地址第三级地址（国家）
			scope.pagedata.item.address = res.detailInfo; // 详细收货地址信息
			scope.pagedata.item.mobile = res.telNumber; // 收货人手机号码
			scope.$evalAsync();
		  },
		  fail: function (res) {
			console.log('fail');console.log(res)
		  }
	});
}
	</script>
</div>
